package com.zhuss.product.processor;

import java.util.*;

import com.zhuss.enums.StartStopEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.product.hotLine.CreateHotLineBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.product.db.dao.ext.HotLineDao;
import com.zhuss.product.db.entity.HotLine;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.DzcxException;
import com.zhuss.util.JsonUtil;


/**
 * @description: 热门线路创建
 * @author: zhushanshuo
 * @create: Mon Jan 11 09:20:35 CST 2021
 **/
@Component("hotLineCreate")
public class HotLineCreate extends AbstractProcessor<Object, CreateHotLineBo> implements Processor<Object, CreateHotLineBo> {

    @Autowired
    private HotLineDao hotLineDao;
    
    @Autowired
	@Qualifier("hotLineRead")
	private HotLineRead hotLineRead;
    
    
    /**
     * 校验
     */
    @Override
    public void check(CreateHotLineBo bo) throws DzcxException {
    	// TODO 创建 热门线路 校验， 请补充
    	String name = bo.getName();
    	if (name == null || "".equals(name.trim())) {
    		// throw new DzcxException(ExceptionCode.热门线路name为空);
    	}
    	
    	List<HotLine> list = hotLineRead.list(name);
    	if (!list.isEmpty()) {
    		// throw new DzcxException(ExceptionCode.热门线路name已存在);
    	}
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(CreateHotLineBo param) {
    	HotLine record = new HotLine();
    	record.setName(param.getName());
    	record.setHotLineNo(param.getHotLineNo());
    	record.setStartPointName(param.getStartPointName());
    	record.setEndPointName(param.getEndPointName());
    	record.setFirstTime(param.getFirstTime());
//    	record.set
    	record.setRideType(param.getRideType());
    	record.setTotal(param.getTotal());
    	record.setSelled(param.getSelled());
		record.setStatus(param.getStatus() == null ? StartStopEnum.启用.key() : param.getStatus());
    	record.setPrice(param.getPrice());
    	record.setSort(param.getSort());

    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	hotLineDao.create(record);
    	param.setTargetId(record.getHotLineId());
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(CreateHotLineBo param) throws DzcxException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.商品.key());
    	record.setAction(LogActionEnum.热门线路创建.key());
    	record.setTargetId(param.getTargetId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
